﻿#include "UCustomListUMG.h"

#include "ListLibrary/ListUIStyle.h"

UCustomListUMG::UCustomListUMG()
	: MaxValue(100)
	  , GrowValue(20)
{
}

TSharedRef<SWidget> UCustomListUMG::RebuildWidget()
{
	CustomList = SNew(SCustomList);
	return CustomList.ToSharedRef();
}

const FText UCustomListUMG::GetPaletteCategory()
{
	return FText::FromString(TEXT("小辉辉"));
}

//资源释放
void UCustomListUMG::ReleaseSlateResources(bool bReleaseChildren)
{
	Super::ReleaseSlateResources(bReleaseChildren);
	CustomList.Reset();
}

void UCustomListUMG::UpDataList(TMap<FString, FCustomListInfo> ListData)
{
	if (MaxValue > MinValue && (GrowValue > MaxValue || GrowValue < MinValue) || MaxValue < MinValue && (GrowValue < MaxValue ||GrowValue > MinValue))
		GrowValue = 0;
	
	if (GrowValue == 0)
	{
		GrowValue = (MaxValue - MinValue) / 5;
	}
	GrowValue = FMath::Abs(GrowValue);
	if (WarningValue > MaxValue && MaxValue > MinValue || WarningValue < MaxValue && MaxValue < MinValue)
	{
		WarningValue = MaxValue;
	}
	
	//表格中的最大值
	CustomList->MaxValue = MaxValue;
	//表格中的最小值
	CustomList->MinValue = MinValue;
	//递增区间
	CustomList->GrowValue = GrowValue;
	//柱子的个数
	CustomList->PillarNum = PillarNum;
	//启用柱子背景
	CustomList->PillarBg = PillarBg;
	//显示警戒线
	CustomList->ShowWarningLine = ShowWarningLine;
	//警戒值
	CustomList->WarningValue = WarningValue;
	//显示折线
	CustomList->ShowZheLine = ShowZheLine;
	//显示圆
	CustomList->ShowYuan = ShowYuan;
	//显示标题
	CustomList->ShowTitle = ShowTitle;
	//表格宽度
	CustomList->TableWidth = TableWidth;
	CustomList->UpDataList(ListData);
}

void UCustomListUMG::MySynchronizeProperties()
{
	SynchronizeProperties();
}

//更新UI
void UCustomListUMG::SynchronizeProperties()
{
	Super::SynchronizeProperties();
	CustomList->UpDataTitleName(Title);
	CustomList->UpDataOneInfoName(OneInfo);
	CustomList->UpDataTwoInfoName(TwoInfo);
	CustomList->UpDataThreeInfoName(ThreeInfo);
	CustomList->UpDataFourInfoName(CustomInfo);

	if (MaxValue > MinValue && (GrowValue > MaxValue || GrowValue < MinValue) || MaxValue < MinValue && (GrowValue < MaxValue ||GrowValue > MinValue))
		GrowValue = 0;
	
	if (GrowValue == 0)
	{
		GrowValue = (MaxValue - MinValue) / 5;
	}
	GrowValue = FMath::Abs(GrowValue);
	if (WarningValue > MaxValue && MaxValue > MinValue || WarningValue < MaxValue && MaxValue < MinValue)
	{
		WarningValue = MaxValue;
	}
	//表格中的最大值
	CustomList->MaxValue = MaxValue;
	//表格中的最小值
	CustomList->MinValue = MinValue;
	//递增区间
	CustomList->GrowValue = GrowValue;
	//柱子的个数
	CustomList->PillarNum = PillarNum;
	//启用柱子背景
	CustomList->PillarBg = PillarBg;
	//显示警戒线
	CustomList->ShowWarningLine = ShowWarningLine;
	//警戒值
	CustomList->WarningValue = WarningValue;
	//显示折线
	CustomList->ShowZheLine = ShowZheLine;
	//显示圆
	CustomList->ShowYuan = ShowYuan;
	//显示标题
	CustomList->ShowTitle = ShowTitle;
	//表格宽度
	CustomList->TableWidth = TableWidth;
	//重新绘制表格
	CustomList->UpdataCustomList();
}
